import {defineStore} from "pinia";
const file=JSON.parse( sessionStorage.getItem('file')? sessionStorage.getItem('file'):null)
const yc=JSON.parse( sessionStorage.getItem('yc')? sessionStorage.getItem('yc'):null)
const wd=JSON.parse( sessionStorage.getItem('wd')? sessionStorage.getItem('wd'):null)
const xq=JSON.parse( sessionStorage.getItem("xq")? sessionStorage.getItem("xq"):null)
const xq1=JSON.parse( sessionStorage.getItem("xq1")? sessionStorage.getItem("xq1"):null)
const t1=JSON.parse( sessionStorage.getItem("t1")? sessionStorage.getItem("t1"):null)
const t2=JSON.parse( sessionStorage.getItem("t2")? sessionStorage.getItem("t2"):null)
const t3=JSON.parse( sessionStorage.getItem("t3")? sessionStorage.getItem("t3"):null)
const t4=JSON.parse( sessionStorage.getItem("t4")? sessionStorage.getItem("t4"):null)
const ts4=JSON.parse( sessionStorage.getItem("ts4")? sessionStorage.getItem("ts4"):null)
const sx=JSON.parse( sessionStorage.getItem("sx")? sessionStorage.getItem("sx"):null)
const data=JSON.parse( sessionStorage.getItem("data")? sessionStorage.getItem("data"):null)
const data1=JSON.parse( sessionStorage.getItem("data1")? sessionStorage.getItem("data1"):null)
const select=JSON.parse( sessionStorage.getItem("select")? sessionStorage.getItem("select"):null)
const select_u=JSON.parse( sessionStorage.getItem("select_u")? sessionStorage.getItem("select_u"):null)
const u2=JSON.parse( sessionStorage.getItem("u2")? sessionStorage.getItem("u2"):null)
const site=JSON.parse(sessionStorage.getItem("st")? sessionStorage.getItem("st"):null)
const zs=JSON.parse(sessionStorage.getItem("zs")? sessionStorage.getItem("zs"):null)
const jkwdstartdate=JSON.parse(sessionStorage.getItem("jkwdstartdate")? sessionStorage.getItem("jkwdstartdate"):null)
const jkwdenddate=JSON.parse(sessionStorage.getItem("jkwdenddate")? sessionStorage.getItem("jkwdenddate"):null)
const zytzstartdate=JSON.parse(sessionStorage.getItem("zytzstartdate")? sessionStorage.getItem("zytzstartdate"):null)
const zytzenddate=JSON.parse(sessionStorage.getItem("zytzenddate")? sessionStorage.getItem("zytzenddate"):null)
const Tz_End=JSON.parse(sessionStorage.getItem("Tz_End")? sessionStorage.getItem("Tz_End"):null)
console.log(file)
console.log(wd)
export const userStore = defineStore("user", {
    state: () => {
        return {
          jkwdstartdate:jkwdstartdate?jkwdstartdate:null,
          jkwdenddate:jkwdenddate?jkwdenddate:null,
          zytzstartdate:zytzstartdate?zytzstartdate:null,
          zytzenddate:zytzenddate?zytzenddate:null,
          detailInfo1:null,
          detailInfo2:null,
          detailInfo3:null,
          detailInfo4:null,
          sex:null,
          yclist:yc?yc:[],
          optionser:file?file:[],
          jkwd:wd?wd:[],
          xqlist:xq?xq:{},
          xqlist1:xq1?xq1:{},
          tableData1:t1?t1:[],
          tableData2:t2?t2:[],
          tableData3:t3?t3:[],
          tableData4:t4?t4:[],
          tableDatas4:ts4?ts4:[],
          tableDatasx:sx?sx:[],
          Get_CheckSub_Data:data?data:{},
          Get_CheckSub_Data1:data1?data1:{},
          xg4:{},
          select:select?select:[],
          select_u:select_u?select_u:[],
          u2:u2?u2:'',
          site:site?site:'',
          ZytzQuestions:zs?zs:[],
           Tz_End:Tz_End?Tz_End:{}
        }
    },
    getters: {
       
    },
    actions: {
      setUserInfo(obj1) {
        this.detailInfo1 = obj1;
      },
      setUserInfo1(obj) {
        this.detailInfo2 = obj
      },
      setUserInfo2(obj) {
        this.detailInfo3 = obj
      },
      setUserInfo3(obj) {
        this.detailInfo4 = obj
      },
      updateOption(options) {
        this.sex = options;
        // console.log(this.$state.optionser)
      },
      saveState() {
        sessionStorage.setItem('file', JSON.stringify(this.optionser));
        console.log(this.state)
      },
      restoreState() {
        // 从 sessionStorage中恢复状态
        this.optionser = JSON.parse( sessionStorage.getItem('file') || '{}')
        this.$patch(this.optionser)
      }
    },
    // persist: {
    //   enabled: true,//开启数据持久化
    // }
})



